<?php

namespace App\Models\Traits;

use App\Util\LoginUtil;
use Illuminate\Database\Eloquent\Model;

trait HasGuardsScope
{
    public static function bootHasGuardsScope(): void
    {
        static::creating(function(Model $model){
            $user_info = LoginUtil::getUserInfo();
            $guards = data_get($user_info,'guards','admin');
            if (!empty($guards)&& empty(data_get($model, 'guards'))) {
                $model->setAttribute('guards', $guards);
            }
        });
    }
}
